﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ThumbnailRender : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            const String IMAGE_PATH = "img";
            const String IMAGE_WIDTH = "width";

            String imageUrl = Server.MapPath(Request.QueryString[IMAGE_PATH]);
            int width;
            int height;
            int.TryParse(Request.QueryString[IMAGE_WIDTH], out width);

            System.Drawing.Image image = System.Drawing.Image.FromFile(imageUrl);

            // Calculate size of new image follows old width
            height = image.Height * width / image.Width;
            System.Drawing.Bitmap img = new System.Drawing.Bitmap(image, new System.Drawing.Size(width, height));

            //Render
            Response.ContentType = System.Drawing.Imaging.ImageFormat.Jpeg.ToString();
            img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            image.Dispose();
            img.Dispose();
        }
        catch (Exception)
        {
        }
    }
}